<?php
   /***************************************************************************************************
     PROGRAM DESCRIPTION :  PROGRAM TO VIEW AND EDIT THE joinpgms according to  category
      VARIABLES          :

  //*************************************************************************************************/
//Last Modified By DPT on May/25/05 to fix issues with HTML
    include_once 'includes/constants.php';
    include_once 'includes/functions.php';




    $partners=new partners;
    $partners->connection($host,$user,$pass,$db);
    $SortBy  =$_GET['SortBy'];
    $cat	 =$_GET['cat'];
    $pgm     =trim($_GET['pgm']);                 //selected pgm
    $newpgm	 =$pgm;
    $OrderBy =trim(stripslashes($_GET['OrderBy']));
    if(empty($OrderBy))   $OrderByValue ="desc";
    if($OrderBy=="desc")
    {
        $image="images/up.gif";
        $OrderByValue ="asc"  ;
    }
    else
    {
         $OrderByValue ="desc"  ;
         $image="images/dawn.gif";
     }

   /* $sort_url   =trim(stripslashes($_GET['sort_url']));
    $sort_name  =trim(stripslashes($_GET['sort_name']));
    $sort_click =trim(stripslashes($_GET['sort_click']));
    $sort_sale  =trim(stripslashes($_GET['sort_sale']));
    $sort_lead  =trim(stripslashes($_GET['sort_lead']));

    if(empty($sort_url)) $sort_url   ="asc";
    if(empty($sort_name)) $sort_name  ="asc";
    if(empty($sort_click)) $sort_click ="asc";
    if(empty($sort_sale)) $sort_sale  ="asc";
    if(empty($sort_lead)) $sort_lead  ="asc";*/





     /*************************************listing new category****************/
     $sql		="select * from partners_program where program_status like 'active'  order by program_date desc";
     $rt1		=mysql_query($sql);
     $count1	=mysql_num_rows($rt1);
     $i=0;

     while($row=mysql_fetch_object($rt1))
     {
     $link[$i]=stripslashes(($row->program_url));   //part of url to display
     $pgm[$i]=$row->program_id;                                //stroring in array
     $i=$i+1;
     }
     /*************************************************************************/


     /******************listing category**************************************/
     $sql="select * from partners_category";
     $ret=mysql_query($sql);
     $i=0;
     $j=0;
     $k=0;
     $count=mysql_num_rows($ret);
     while($row=mysql_fetch_object($ret))
               {
                   $cat[$i]=$row->cat_name;
                   $sql="select * from partners_merchant,partners_program where program_status='active' and merchant_category='$cat[$i]' and merchant_id=program_merchantid"   ;
                   $result=mysql_query($sql);
                   $no[$i]="(".mysql_num_rows($result).")";          //finding pgm of specified category
                   $i=$i+1;
              }

    /**************************************************************************/



 $Err		=$_GET['Err'];
 $Action	=$_GET['Action'];

 if ($Action=="affiliate")
    $aff="selected = 'selected' ";
 else
     $mer="selected = 'selected' ";
?>

<table width="775" border="0" align="center" class="outtbl" cellpadding="0" cellspacing="0">
  <tr>
    <td width="215" align="left" valign="top" class="lftnavbg">
      <table width="100%"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td width="215" height="26" align="left" valign="top" class="lanbg"><table width="175"  border="0" cellspacing="0">
            <tr>
              <td width="215" align="right" valign="middle">
              <!-- Language: <select name="select2" class="style3">
                <option>English</option>
              </select>
			  -->
			  <? include_once "language_select.php"; ?>
			  </td>
            </tr>
          </table></td>
        </tr>
      </table>

        <table width="190"  border="0" cellspacing="0" cellpadding="15">
          <tr>
            <td width="215">
              <form name="login" action="login_validate.php" method="post">
                <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td height="1" colspan="2" bgcolor="#7D7D7D"></td>
                  </tr>
                  <tr>
                    <td height="25" colspan="2" ><div align="center"><img src="images/login.gif" width="111" height="17" alt="" /></div></td>
                  </tr>
                  <tr>
                    <td height="1" colspan="2" bgcolor="#7D7D7D"></td>
                  </tr>
                  <tr>
                    <td height="5" colspan="2" ><span class="style6">
                      <?=$Err?>
                    </span></td>
                  </tr>
                  <tr>
                    <td height="15" colspan="2" class="style5"><?=$lang_Choose?>
                      :</td>
                  </tr>
                  <tr>
                    <td height="20" colspan="2" ><select name="flag" class="style3">
                        <option <?=$mer?> value="merchant">
                        <?=$lang_Merchants?>
                        </option>
                        <option <?=$aff?> value="affiliate">
                        <?=$lang_Affiliates?>
                        </option>
                    </select></td>
                  </tr>
                  <tr>
                    <td height="15" colspan="2" ><span class="style5">
                      <?=$lang_Username?>
                      :</span></td>
                  </tr>
                  <tr>
                    <td height="20" colspan="2" ><input name="login" type="text" class="style3" value="" size="25" /></td>
                  </tr>
                  <tr>
                    <td height="15" colspan="2" class="style5"><?=$lang_Password?>
                      :</td>
                  </tr>
                  <tr>
                    <td width="60%"><input  name="password" type="password" class="style3" value="" size="15"/></td>
                    <td width="60" height="20" class="enter"><div class="sbt" onclick="document.login.submit()" >&nbsp;&nbsp;&nbsp;&nbsp; Enter</div></td>
                  </tr>
                  <tr>
                    <td height="15" colspan="2" ><a href="#" onclick="viewLink()">
                      <?=$lang_Forgot?>
                      ? </a></td>
                  </tr>
                  <tr>
                    <td height="5" colspan="2" ></td>
                  </tr>
                  <tr>
                    <td height="1" colspan="2" bgcolor="#7D7D7D"></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2" ></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2" ><div align="justify">
                        <?=$lang_iPartnersmanager?>
                    </div></td>
                  </tr>
                  <tr>
                    <td height="10" colspan="2" ></td>
                  </tr>
                  <tr>
                    <td height="1" colspan="2" bgcolor="#797979"></td>
                  </tr>
                </table>
            </form></td>
          </tr>
        </table></td>
    <td height="100%" rowspan="2" align="left" valign="top"><table width="95%" border="0" cellpadding="0" cellspacing="0">
      <tr>
        <td align="left" valign="top">

<?php
	if($count>0)
	{
?>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="24" height="26"> <img src="images/innerbox1_01.gif" width="24" height="26" alt="" /></td>
              <td width="100%" height="26" bgcolor="#2676d1"><div align="center" class="style4"><?=$lang_cat?></div></td>
              <td height="26" width="131" colspan="2" align="right" class="rtborder">
                <div align="right" class="rtborder"><img src="images/innerbox1_03.gif" width="131" height="26" alt="" /></div></td>
            </tr>
            <tr align="left">
              <td height="2" colspan="4" class="ltrtbrdrw" ><table width="100%"  border="0" cellspacing="5" cellpadding="5">
                  <tr>
                    <td align="center"><table border="0"  width="100%" id="autonumber1" class="tablewbdr" cellspacing="3" >


               <?
               while($j<$count )      //listing
               {
               ?>
                <tr>
                 <td width="50%" align="center" class="grid1" height="10"><a href="index.php?Act=directory&amp;joinstatus=catwise&amp;category=<?=$cat[$j]?>"><?=$cat[$j]?><?=$no[$j]?></a></td>
					<td>
                    </td>
                 <td width="50%" align="center" class="grid1" height="10"><a href="index.php?Act=directory&amp;joinstatus=catwise&amp;category=<?=$cat[$j+1]?>"><?=$cat[$j+1]?><?=$no[$j+1]?></a></td>
               </tr>
               <?
               $j=$j+2;
               }
                ?>
             </table></td>
                    </tr>
              </table></td>
            </tr>
            <tr>
              <td height="26" colspan="3" class="lftborder"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td width="410" height="26" align="left" valign="bottom"><table width="100%"  border="0" align="left" cellpadding="0" cellspacing="0">
                        <tr>
                          <td height="21">&nbsp;</td>
                        </tr>
                        <tr>
                          <td height="5" bgcolor="#d2d2d2"></td>
                        </tr>
                    </table></td>
                    <td width="21" height="26"><img src="images/innerbox1_06.gif" width="21" height="26" alt="" /></td>
                  </tr>
              </table></td>
              <td height="26" align="left" valign="top">
                <div align="center">
                  <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="106" height="26" bgcolor="#D2D2D2">&nbsp;</td>
                      <td width="24" height="26"><img src="images/innerbox1_08.gif" width="24" height="26" alt=""/></td>
                    </tr>
                  </table>
              </div></td>
            </tr>
          </table>
<?php
	}//end of checking for records

                            $maxCount = 10;
              				if($count1<$maxCount) $maxCount = $count1;
	if($maxCount>0)
	{
?>

            <br/>
            <table width="100%" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="24" height="26"> <img src="images/innerbox1_01.gif" width="24" height="26" alt="" /></td>
                <td width="100%" height="26" bgcolor="#2676d1"><div align="center" class="style4"><?=$lang_newpgm?></div></td>
                <td height="26" width="131" colspan="2" align="right" class="rtborder">
                  <div align="right"><img src="images/innerbox1_03.gif" width="131" height="26" alt="" /></div></td>
              </tr>
              <tr align="left">
                <td height="2" colspan="4" class="ltrtbrdrw" ><table width="100%"  border="0" cellspacing="5" cellpadding="5">
                    <tr>
                      <td align="center"><table border="0" cellspacing="3" width="100%" id="AutoNumber2" class="tablewbdr" >
                        <?

               				while($k<$maxCount)
               				{
               				?>
                        		<tr>
                          			<td width="100%" align="center" class="grid1"><a href="index.php?Act=directory&amp;joinstatus=pgmwise&amp;pgm=<?=$pgm[$k]?>">
                            		<?=$link[$k]?>
                         		 </a></td>
                        		</tr>
                       		 <?
               		   			$k=$k+1;
               			}

               ?>
                      </table></td>
                    </tr>
                </table></td>
              </tr>
              <tr>
                <td height="27" colspan="3" class="lftborder"><table width="100%"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td width="410" height="26" align="left" valign="bottom"><table width="100%"  border="0" align="left" cellpadding="0" cellspacing="0">
                          <tr>
                            <td height="21">&nbsp;</td>
                          </tr>
                          <tr>
                            <td height="5" bgcolor="#d2d2d2"></td>
                          </tr>
                      </table></td>
                      <td width="21" height="26"><img src="images/innerbox1_06.gif" width="21" height="26" alt="" /></td>
                    </tr>
                </table></td>
                <td height="26" align="left" valign="top">
                  <div align="center">
                    <table width="100%"  border="0" cellspacing="0" cellpadding="0">
                      <tr>
                        <td width="106" height="26" bgcolor="#d2d2d2">&nbsp;</td>
                        <td width="24" height="26"><img src="images/innerbox1_08.gif" width="24" height="26" alt=""/></td>
                      </tr>
                    </table>
                </div></td>
              </tr>
            </table>
<?php
	}//end of checking for records
?>
            <br/>
            <table width="100%" border="0" align="left" cellpadding="0" cellspacing="0">
              <tr bgcolor="#ffa200">
                <td width="5%" height="26" align="left" valign="top"> <img src="images/innerbox2_01.gif" width="24" height="26" alt=""/> </td>
                <td width="95%" align="left" valign="top"><table width="100%" border="0" align="center" class="tablewbdr">
                    <tr align="left" valign="middle">
                      <td width="30%" >
                        <p align="center">
                          <?if($SortBy=="program_url"){?>
                          <a href="index.php?Act=directory&amp;pgm=<?=$pgm?>&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=program_url&amp;OrderBy=<?=$OrderByValue?>"><img src="<?=$image?>" height="10" width="10" border="0"><?=$lang_pgm?></a>
                          <?}else{?>
                          <a href="index.php?Act=directory&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=program_url&amp;OrderBy=<?=$OrderByValue?>&amp;pgm=<?=$newpgm?>"><?=$lang_pgm?></a>
                          <?}?>
                      <font color="#F2F2F2"> </font></p></td>
                      <td width="20%" bgcolor="#FFA200">
                        <p align="center">
                          <?if($SortBy=="merchant_firstname"){?>
                          <a href="index.php?Act=directory&amp;pgm=<?=$newpgm?>&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=merchant_firstname&amp;OrderBy=<?=$OrderByValue?>"><img src="<?=$image?>" height="10" width="10" border="0"><?=$lang_merchant?></a>
                          <?}else{?>
                          <a href="index.php?Act=directory&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=merchant_firstname&amp;pgm=<?=$newpgm?>&amp;OrderBy=<?=$OrderByValue?>"><?=$lang_merchant?></a>
                          <?}?>
                      <font color="#F2F2F2"> </font></p></td>
                      <td width="10%" bgcolor="#FFA200">
                        <p align="center">
                          <?if($SortBy=="firstlevel_clickrate"){?>
                          <a href="index.php?Act=directory&amp;pgm=<?=$newpgm?>&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=firstlevel_clickrate&amp;OrderBy=<?=$OrderByValue?>"><img src="<?=$image?>" height="10" width="10" border="0"><?=$lang_click?> </a>
                          <?}else{?>
                          <a href="index.php?Act=directory&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=firstlevel_clickrate&amp;pgm=<?=$newpgm?>&amp;OrderBy=<?=$OrderByValue?>"><?=$lang_click?> </a>
                          <?}?>
                      <font color="#F2F2F2"> </font></p></td>
                      <td width="15%" bgcolor="#FFA200">
                        <p align="center">
                          <?if($SortBy=="firstlevel_leadrate"){?>
                          <a href="index.php?Act=directory&amp;pgm=<?=$newpgm?>&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=firstlevel_leadrate&amp;OrderBy=<?=$OrderByValue?>"><img src="<?=$image?>" height="10" width="10" border="0"><?=$lang_lead?></a>
                          <?}else{?>
                          <a href="index.php?Act=directory&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=firstlevel_leadrate&amp;pgm=<?=$newpgm?>&amp;OrderBy=<?=$OrderByValue?>"><?=$lang_lead?></a>
                          <?}?>
                      <font color="#F2F2F2"> </font></p></td>
                      <td width="10%" bgcolor="#FFA200">
                        <p align="center">
                          <?if($SortBy=="firstlevel_salerate"){?>
                          <a href="index.php?Act=directory&amp;pgm=<?=$newpgm?>&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=firstlevel_salerate&amp;OrderBy=<?=$OrderByValue?>"><img src="<?=$image?>" height="10" width="10" border="0"><?=$lang_sale?></a>
                          <?}else{?>
                          <a href="index.php?Act=directory&amp;category=<?=$category?>&amp;joinstatus=<?=$joinstatus?>&amp;SortBy=firstlevel_salerate&amp;pgm=<?=$newpgm?>&amp;OrderBy=<?=$OrderByValue?>"><?=$lang_sale?></a>
                          <?}?>
                      <font color="#F2F2F2"> </font></p></td>
                      <td width="100%" bgcolor="#FFA200">
                      <p align="center"><font color="#F2F2F2"><?=$lang_action?></font></p></td>
                    </tr>
                </table></td>
              </tr>
              <tr>
                <td height="2" colspan="2" class="ltrtbrdr1"><?
         include "directory_help.php";
           ?>
                    <p></p></td>
              </tr>
              <tr>
                <td height="26" colspan="2" bgcolor="#d2d2d2" class="lftborder">
                  <div align="right"><img src="images/innerbox2_07.gif" width="25" height="26" alt=""/></div></td>
              </tr>
            </table>

			  <p>&nbsp;            </p></td>
      </tr>
    </table>
      <p>&nbsp;</p></td>
  </tr>
  <tr>
    <td width="215" height="23" align="left" valign="bottom" class="lftnavbg"><img src="images/lft_bt_13.gif" width="215" height="23" alt=""/></td>
  </tr>
</table>

<script language="javascript" type="text/javascript">
           function viewLink()
                {

                   url="forgotpass.php";
                   nw = open(url,'new','height=200,width=450,scrollbars=yes');
                   nw.focus();
                }
 </script>